package com.imagination.applet.domain.photo.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.BooleanUtils;

import java.util.ArrayList;
import java.util.List;

@Builder
@NoArgsConstructor
@AllArgsConstructor
@Data
public class UserPhotosResult {

    private List<UserPhoto> goodPhotos;

    private List<UserPhoto> badPhotos;

    public static UserPhotosResult of(List<UserPhoto> userPhotoList) {
        List<UserPhoto> good = userPhotoList.stream().filter(p -> BooleanUtils.isTrue(p.getAvailable())).toList();
        List<UserPhoto> bad = userPhotoList.stream().filter(p -> BooleanUtils.isNotTrue(p.getAvailable())).toList();
        return UserPhotosResult.builder()
                .goodPhotos(good)
                .badPhotos(bad)
                .build();
    }

    public static UserPhotosResult ok(List<UserPhoto> userPhotoList, List<String> success) {
        List<UserPhoto> good = new ArrayList<>();
        List<UserPhoto> bad = new ArrayList<>();
        for (UserPhoto userPhoto : userPhotoList) {
            for (String s : success) {
                if(s.equals(userPhoto.getPhotoPath())){
                    good.add(userPhoto);
                }
            }
        }
        return UserPhotosResult.builder()
                .goodPhotos(good)
                .badPhotos(bad)
                .build();
    }

}
